<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var largestNumber = function (nums) {
      nums.sort((a, b) => {
        var stra = b.toString() + a.toString(), strb = a.toString() + b.toString();
        if (stra > strb) {
          return 1
        } else {
          return -1
        }
      });
      if (nums[0] == 0) return '0'
      return nums.join('');
    };
    console.log(largestNumber(nums = [3, 30, 34, 5, 9]))
  </script>
</body>

</html>